package jude.java.money.article;

import jude.java.util.WebUtils;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;

public class Publisher {
	private static final String ENCODING = "GBK";
	
	public static void main(String[] args) {
		String[][] sites = SITES;
		for (int i = 0; i < sites.length; i++) {
			String[] site = sites[i];
			String url = site[0] + PATH;
			new Publisher().publish(url, "123", "456");
//			break;
		}
	}
	
	private HttpClient client;
	
	public void publish(String url, String title, String content) {
		initHttpClient();
		PostMethod post = new PostMethod(url);
		WebUtils.pretendRequestHeader(post);
		post.addParameter("Subject", title);
		post.addParameter("Message", content);
//		post.setFollowRedirects(true);
		try {
			int state = client.executeMethod(post);
			if (state != HttpStatus.SC_OK)
				return;
			String response = WebUtils.getResponse(post, 81920, ENCODING);
			if (response != null && response.indexOf("提交成功") > 0) {
				System.out.println("成功 " + url);
			} else {
				System.out.println("失败 " + url);
			}
		} catch (Exception e) {
			System.out.println("失败 " + url);
		}
	}
	
	protected void initHttpClient() {
		client = new HttpClient();
		client.getHttpConnectionManager().getParams().setConnectionTimeout(20000);
		client.getHttpConnectionManager().getParams().setSoTimeout(60000);
	}
	
	private static final String PATH = "ruigeadmin/publish_newsarticle.php";

	public static final String[][] SITES = {
//		"http://127.0.0.1/",
		{"http://www.outlet-uggs.us/",			"outlet uggs"},
		{"http://www.uggoutlet.us/",			"ugg outlet"},
		{"http://www.ugg-boots-outlet.us/",		"ugg boots outlet"},
		{"http://www.ugg-australia-boots.us/",	"ugg australia boots"},
		{"http://www.uggsbootsoutlet.us/",		"uggsbootsoutlet"},
		{"http://www.uggs-boots.us/",			"uggs boots"},
		{"http://www.australia-uggs.us/",		"uggs australia"},
		{"http://www.uggshoesboots.us/",		"uggs shoes"},
		{"http://www.ugg-uggs.us/",				"uggs"},
		{"http://www.ugg-onsale.us/",			"uggs on sale"},
		{"http://www.ugg-on-sale.us/",			"ugg on sale"},
		{"http://www.boots-uggs.us/",			"ugg boots"},
		{"http://www.toryburch-shoes.us/",		"tory burch shoes"},
		{"http://www.fashioning.us/",			"fashioning"},
		{"http://www.all-luxury.us/",			"All luxury"},
		{"http://www.wholesale-clothingshoes.com/","wholesale clothingshoes"},
		{"http://www.watches-bvlgari.com/",		"watches bvlgari"},
		{"http://www.watches-rolex.us/",		"watches rolex"},
		{"http://www.handbags-coach.us/",		"handbags coach"},
		{"http://www.herve-leger-dress.us/",	"herve leger dress"},
		{"http://www.alexander-wang.us/",		"alexander wang u"},
		{"http://www.wangalexander.com/",		"alexander wang c"},
		{"http://www.chi-flatiron.us/",			"chi flat iron"},
		{"http://www.hair-straighteneres.co.uk/","hair-straighteneres"},
		{"http://www.www.alexander-mcqueen.us/","mcqueen us"},
		{"http://www.mukluk-boots.com/",		"mukluk boots"},
		{"http://www.canadian-mukluks.com/",	"canadian mukluks"},
	};
}
